<template>
	<view class="page index">
		<view class="form">
			<common-input
			  title="开票单位名称" 
				placeholder="默认填写客户名称,可修改" 
				v-model="customerName"
				:border-bottom="false"
			>
			</common-input>
			<common-input
			  title="纳税人识别码" 
				placeholder="请填写开票税号" 
				v-model="code"
				:border-bottom="false"
			>
			</common-input>
			<common-input
			  title="地址" 
				placeholder="请填写开票单位地址" 
				v-model="address"
				:border-bottom="false"
				:require="false"
			>
			</common-input>
			<common-input
			  title="电话" 
				placeholder="请填写开票单位电话" 
				v-model="phone"
				:border-bottom="false"
				:require="false"
			>
			</common-input>
			<common-input
			  title="开户行" 
				placeholder="请填写开户行" 
				v-model="bank"
				:require="false"
				:border-bottom="false"
			>
			</common-input>
			<common-input
			  title="账号" 
				placeholder="请填写银行账号" 
				v-model="account"
				:require="false"
				:border-bottom="false"
			>
			</common-input>
			<picker mode="selector" :value="requireIndex" :range="requireList" @change="selectRequire">
				<view class="picker">
					<common-input 
					  title="开票要求" 
					  placeholder="请选择开票要求" 
					  v-model="requireList[requireIndex]" 
					  :select="true" 
					  :disabled="true" 
						:require="false"
					>
					</common-input>
				</view>
			</picker>
			<view class="text">
				<view class="title">
					<view>
						备注
					</view>
					<!-- <view class="require"></view> -->
				</view>
				<textarea v-model="remark" placeholder="请输入备注消息" placeholder-class="place"></textarea>
			</view>
		</view>
		<view class="footer">
			<button @click="save">保存</button>
		</view>
	</view>
</template>

<script>
	import commonInput from "@/components/commonInput.vue";
	import {createInvoiceApi} from "@/api/customer_api.js";
	export default{
		data() {
			return{
				id: 0, //客户id
				code: '',
				customerName: '',
				address: '',
				phone:'',
				bank:'',
				account:'',
				requireIndex: 0,
				requireList:['优先专票', '优先普票', '无要求'],
				remark:''
			}
		},
		components: {
			commonInput,
		},
		onLoad(e) {
			this.id = e.id;
			this.customerName = e.name;
		},
		methods:{
			selectRequire(e){
				this.requireIndex = e.detail.value;
			},
			updatefiles(e){
				console.log(e,'===============')
			},
			save(){
				if(this.customerName == ''){
					uni.showToast({
						icon: 'none',
						title: '开票单位不能为空',
					})
					return;
				}
				if(this.code == ''){
					uni.showToast({
						icon: 'none',
						title: '纳税人识别码不能为空',
					})
					return;
				}
				uni.showLoading({
					mask: true,
					title: '加载中...'
				})
				createInvoiceApi({
					customerId: this.id,
					companyName: this.customerName,
					dutyParagraph: this.code,
					companyAddress: this.address,
					telephone: this.phone,
					bankName: this.bank,
					bankAccount: this.account,
					requirement: this.requireIndex,
					remark: this.remark
				}).then(() => {
					uni.hideLoading();
					uni.showToast({
						icon: 'success',
						title: '创建成功'
					})
					setTimeout(() => {
						uni.navigateBack()
					},1500)
				}).catch(() => {
					uni.hideLoading()
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/common/style/customicons.scss";
	.index{
		padding: 24rpx 0;
		@include flex-c;
		.form{
			flex: 1 0 0;
			overflow: auto;
			.text{
				border-bottom: 4rpx #e5e5e5 solid;
				padding: 12rpx 30rpx;
				.title{
					font-size: 28rpx;
					color: #101010;
					padding: 0 0 16rpx;
					display: flex;
					align-items: center;
					.require{
					  height: 28rpx;
					  width: 6rpx;
					  background-color: #c24135;
					  margin-left: 10rpx;
				  }
				}
				textarea{
					font-size: 28rpx;
					color: #909090;
					height: 125rpx;
				}
				.place{
					font-size: 28rpx;
					color: #909090;
				}
			}
			&::-webkit-scrollbar{
				display: none;
			}
		}
		.footer{
			flex: 0 0 auto;
			padding: 24rpx 130rpx;
			button{
				@include button;
				background-color: #198AFA;
				color: #fff;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 28rpx;
				width: 100%;
			}
		}
	}
</style>